package com.yykj.hospital.server.controller;

import com.yykj.common.enums.HospitalOnlineTypeEnum;
import com.yykj.common.vo.ResultVO;
import com.yykj.hospital.client.dto.*;
import com.yykj.hospital.client.dto.banci.DoctorAvailableAppointmentDTO;
import com.yykj.hospital.client.dto.consultation.template.ConsultationVerifyDTO;
import com.yykj.hospital.client.form.OnlineOrderForm;
import com.yykj.hospital.client.form.banci.AppointmentOrderForm;
import com.yykj.hospital.client.form.consultation.ConsultationVerifyForm;
import com.yykj.hospital.server.model.entity.DoctorOnlinePriceSetting;
import com.yykj.hospital.server.service.HospitalDoctorService;
import com.yykj.hospital.server.service.HospitalSettingService;
import com.yykj.hospital.server.service.banci.BanCiSearchService;
import com.yykj.hospital.server.service.banci.BanCiService;
import com.yykj.hospital.server.service.consultation.HospitalConsultationVerifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/proto/hospital")
@Api(tags = "内部使用-医生相关 和 配置")
@Slf4j
public class ProtoHospitalController {
    @GetMapping("/doctor/info/{doctorId}")
    @ApiOperation("医生详情")
    public DoctorDTO info(@PathVariable String doctorId){
        return doctorService.info(doctorId);
    }


    @GetMapping("/config/info/{hospitalId}")
    @ApiOperation("医院配置")
    public HospitalConfigInfo hospitalConfigInfo(@PathVariable Integer hospitalId){
        return hospitalSettingService.getHospitalConfigInfo(hospitalId);
    }

    @GetMapping("/doctor/online/config/{doctorId}")
    @ApiOperation("医生在线问诊价格配置")
    public List<DoctorOnlinePriceSettingDTO> doctorOnlineConfigInfo(@PathVariable String doctorId){
        List<DoctorOnlinePriceSettingDTO> result = new ArrayList<>();
        List<DoctorOnlinePriceSetting> doctorOnlinePriceSettings = hospitalSettingService.viewDoctorOnlinePriceSetting(doctorId);
        for (DoctorOnlinePriceSetting setting:doctorOnlinePriceSettings){
            DoctorOnlinePriceSettingDTO dto = new DoctorOnlinePriceSettingDTO();
            BeanUtils.copyProperties(setting,dto);
            result.add(dto);
        }
        return result;
    }

    @GetMapping("/check/appointment/cnt")
    @ApiOperation("预约挂号 -- 检查医生是否还有号可约 ")
    public DoctorAvailableAppointmentDTO checkAvailableAppointmentCnt(@RequestParam(name = "doctorId") String doctorId,
                                                                      @RequestParam(name = "appointId") Integer appointId){
        return searchService.checkAvailableAppointmentCnt(doctorId,appointId);
    }

    @PutMapping("/change/appointment/cnt")
    @ApiOperation("预约挂号 -- 修改库存")
    public DoctorAvailableAppointmentDTO changeAvailableAppointmentCnt(@RequestBody AppointmentOrderForm form){
        return banCiService.changeAvailableAppointmentCnt(form);
    }

    @GetMapping("/check/online/cnt")
    @ApiOperation("在线问诊 -- 检查医生是否还有号可约 ")
    public DoctorAvailableOnlineDTO checkAvailableOnlineCnt(@RequestParam(name = "doctorId") String doctorId,
                                                            @RequestParam(name = "appointId") Integer appointId,
                                                            @RequestParam(name = "type")HospitalOnlineTypeEnum type){
        return searchService.checkAvailableOnlineCnt(doctorId,appointId,type);
    }

    @PutMapping("/change/online/cnt")
    @ApiOperation("在线问诊 -- 修改库存")
    public DoctorAvailableOnlineDTO changeAvailableOnlineCnt(@RequestBody OnlineOrderForm form){
        return banCiService.changeAvailableOnlineCnt(form);
    }

    @ApiOperation("会诊是否需要后台审核")
    @PostMapping("/consultation/check")
    public List<ConsultationVerifyDTO> consultationCheck(@RequestBody ConsultationVerifyForm form){
        return verifyService.verify(form);
    }

    private HospitalConsultationVerifyService verifyService;

    private BanCiSearchService searchService;

    private HospitalDoctorService doctorService;

    private HospitalSettingService hospitalSettingService;

    private BanCiService banCiService;

    @Autowired
    public void setDoctorService(HospitalDoctorService doctorService) {
        this.doctorService = doctorService;
    }

    @Autowired
    public void setHospitalSettingService(HospitalSettingService hospitalSettingService) {
        this.hospitalSettingService = hospitalSettingService;
    }
    @Autowired
    public void setSearchService(BanCiSearchService searchService) {
        this.searchService = searchService;
    }
    @Autowired
    public void setBanCiService(BanCiService banCiService) {
        this.banCiService = banCiService;
    }
    @Autowired
    public void setVerifyService(HospitalConsultationVerifyService verifyService) {
        this.verifyService = verifyService;
    }
}
